package com.jeespring.shardingjdbc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jeespring.shardingjdbc.entity.Order;
import com.jeespring.shardingjdbc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/select")
    public List<Order> select(@RequestBody Order order) {
        return orderService.select(order);
    }

    @RequestMapping("/selectPage")
    public IPage<Order> selectPage(Order order, int pageNumber, int pageSize) {
        return orderService.selectPage(order, pageNumber, pageSize);
    }

    @RequestMapping("/selectAll")
    public List<Order> selectAll() {
        return orderService.selectAll();
    }

    @RequestMapping("/insert")
    public int insert(@RequestBody Order order) {
        return orderService.insert(order);
    }

    @RequestMapping("/update")
    public int update(@RequestBody Order order) {
        if (order.getId() == null) {
            return 0;
        }
        return orderService.update(order);
    }

    @RequestMapping("/delete")
    public int delete(@RequestBody Order order) {
        if (order.getId() == null) {
            return 0;
        }
        return orderService.delete(order);
    }
}
